let HightState = {
  show() {
    console.log('绿色')
  }
}
let MiddleState = {
  show() {
    console.log('黄色')
  }
}
let LowState = {
  show() {
    console.log('红色')
  }
}

let Battery = {
  amount: 'heigh',
  state: HightState,
  show() {
    this.setState()
    this.state.show()
  },
  setState() {
    let amount = {
      'heigh': () => {
        this.state = HightState
      },
      'middle': () => {
        this.state = MiddleState
      },
      'low': () => {
        this.state = LowState
      }
    }
    amount[this.amount]()
  }
}

Battery.show()
Battery.amount = 'middle'
Battery.show()
Battery.amount = 'low'
Battery.show()